<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Git本地多用户配置 | 方塘</title>
    <meta name="description" content="半亩方塘 记录点滴">
    <meta name="generator" content="VuePress 1.4.0">
    <link rel="icon" href="/pond/favicon.ico">
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/pond/assets/css/0.styles.e7d3875b.css" as="style"><link rel="preload" href="/pond/assets/js/app.ae40f477.js" as="script"><link rel="preload" href="/pond/assets/js/3.4dddd738.js" as="script"><link rel="preload" href="/pond/assets/js/1.78b3a486.js" as="script"><link rel="preload" href="/pond/assets/js/14.0cad3209.js" as="script"><link rel="prefetch" href="/pond/assets/js/10.60d30c62.js"><link rel="prefetch" href="/pond/assets/js/11.2f15c6a5.js"><link rel="prefetch" href="/pond/assets/js/12.1d51f447.js"><link rel="prefetch" href="/pond/assets/js/13.814b881d.js"><link rel="prefetch" href="/pond/assets/js/15.1f5f9717.js"><link rel="prefetch" href="/pond/assets/js/16.76e81153.js"><link rel="prefetch" href="/pond/assets/js/17.b69f6fef.js"><link rel="prefetch" href="/pond/assets/js/18.8b657c1a.js"><link rel="prefetch" href="/pond/assets/js/19.7b986df4.js"><link rel="prefetch" href="/pond/assets/js/20.dcaf37b7.js"><link rel="prefetch" href="/pond/assets/js/4.cd37660a.js"><link rel="prefetch" href="/pond/assets/js/5.066fd35c.js"><link rel="prefetch" href="/pond/assets/js/6.34341067.js"><link rel="prefetch" href="/pond/assets/js/7.05fd4dd8.js"><link rel="prefetch" href="/pond/assets/js/8.5a84398b.js"><link rel="prefetch" href="/pond/assets/js/9.af98ea9c.js">
    <link rel="stylesheet" href="/pond/assets/css/0.styles.e7d3875b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div><div class="theme-container" data-v-319dd33c><div data-v-319dd33c><div id="loader-wrapper" class="loading-wrapper" data-v-4b73742e data-v-319dd33c data-v-319dd33c><div class="loader-main" data-v-4b73742e><div data-v-4b73742e></div><div data-v-4b73742e></div><div data-v-4b73742e></div><div data-v-4b73742e></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-1e2a0cc0 data-v-319dd33c data-v-319dd33c><h3 class="title" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0>方塘</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0><input type="password" value="" data-v-1e2a0cc0> <span data-v-1e2a0cc0>Konck! Knock!</span> <button data-v-1e2a0cc0>OK</button></label> <div class="footer" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0><span data-v-1e2a0cc0><i class="iconfont reco-theme" data-v-1e2a0cc0></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-1e2a0cc0>vuePress-theme-reco</a></span> <span data-v-1e2a0cc0><i class="iconfont reco-copyright" data-v-1e2a0cc0></i> <a data-v-1e2a0cc0><span data-v-1e2a0cc0>zenos</span>
            
          <span data-v-1e2a0cc0>2017 - </span>
          2020
        </a></span></div></div> <div class="hide" data-v-319dd33c><header class="navbar" data-v-319dd33c><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/pond/" class="home-link router-link-active"><img src="/pond/logo.png" alt="方塘" class="logo"> <span class="site-name">方塘</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/pond/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pond/categories/Git/" class="nav-link"><i class="iconfont undefined"></i>
  Git
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Electron/" class="nav-link"><i class="iconfont undefined"></i>
  Electron
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Java/问题解决/" class="nav-link"><i class="iconfont undefined"></i>
  Java/问题解决
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Nginx/" class="nav-link"><i class="iconfont undefined"></i>
  Nginx
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Vue/问题解决/" class="nav-link"><i class="iconfont undefined"></i>
  Vue/问题解决
</a></li></ul></div></div><div class="nav-item"><a href="/pond/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/pond/life/photo.html" class="nav-link"><i class="iconfont reco-message"></i>
  点滴
</a></div><div class="nav-item"><a href="/pond/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Contact
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://www.npmjs.com/~reco_luan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-npm"></i>
  NPM
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/recoluan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://www.jianshu.com/u/cd674a19515e" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-jianshu"></i>
  简书
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/zhlantian" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csdn"></i>
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://www.cnblogs.com/luanhewei/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-bokeyuan"></i>
  博客圆
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://mp.weixin.qq.com/s/mXFqeUTegdvPliXknAAG_A" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-wechat"></i>
  WeChat
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-319dd33c></div> <aside class="sidebar" data-v-319dd33c><div class="personal-info-wrapper" data-v-6c8ffc9c><img src="/pond/avatar.png" alt="author-avatar" class="personal-img" data-v-6c8ffc9c> <h3 class="name" data-v-6c8ffc9c>
    zenos
  </h3> <div class="num" data-v-6c8ffc9c><div data-v-6c8ffc9c><h3 data-v-6c8ffc9c>7</h3> <h6 data-v-6c8ffc9c>文章</h6></div> <div data-v-6c8ffc9c><h3 data-v-6c8ffc9c>4</h3> <h6 data-v-6c8ffc9c>标签</h6></div></div> <hr data-v-6c8ffc9c></div> <nav class="nav-links"><div class="nav-item"><a href="/pond/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pond/categories/Git/" class="nav-link"><i class="iconfont undefined"></i>
  Git
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Electron/" class="nav-link"><i class="iconfont undefined"></i>
  Electron
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Java/问题解决/" class="nav-link"><i class="iconfont undefined"></i>
  Java/问题解决
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Nginx/" class="nav-link"><i class="iconfont undefined"></i>
  Nginx
</a></li><li class="dropdown-item"><!----> <a href="/pond/categories/Vue/问题解决/" class="nav-link"><i class="iconfont undefined"></i>
  Vue/问题解决
</a></li></ul></div></div><div class="nav-item"><a href="/pond/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/pond/life/photo.html" class="nav-link"><i class="iconfont reco-message"></i>
  点滴
</a></div><div class="nav-item"><a href="/pond/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Contact
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://www.npmjs.com/~reco_luan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-npm"></i>
  NPM
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/recoluan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://www.jianshu.com/u/cd674a19515e" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-jianshu"></i>
  简书
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/zhlantian" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csdn"></i>
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://www.cnblogs.com/luanhewei/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-bokeyuan"></i>
  博客圆
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://mp.weixin.qq.com/s/mXFqeUTegdvPliXknAAG_A" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-wechat"></i>
  WeChat
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Git本地多用户配置</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#具体步骤" class="sidebar-link">具体步骤</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_1、清空全局配置" class="sidebar-link">1、清空全局配置</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_2、生成秘钥" class="sidebar-link">2、生成秘钥</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_3、拷贝-pub-文件" class="sidebar-link">3、拷贝 pub 文件</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_4、管理秘钥" class="sidebar-link">4、管理秘钥</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_5、在-gitlab-项目网站中添加-ssh-公钥" class="sidebar-link">5、在 gitlab 项目网站中添加 ssh 公钥</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_6、添加私钥" class="sidebar-link">6、添加私钥</a></li><li class="sidebar-sub-header"><a href="/pond/views/Git/Git%E6%9C%AC%E5%9C%B0%E5%A4%9A%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.html#_7、仓库配置" class="sidebar-link">7、仓库配置</a></li></ul></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-1e2a0cc0 data-v-319dd33c><h3 class="title" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0>Git本地多用户配置</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0><input type="password" value="" data-v-1e2a0cc0> <span data-v-1e2a0cc0>Konck! Knock!</span> <button data-v-1e2a0cc0>OK</button></label> <div class="footer" style="display:none;" data-v-1e2a0cc0 data-v-1e2a0cc0><span data-v-1e2a0cc0><i class="iconfont reco-theme" data-v-1e2a0cc0></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-1e2a0cc0>vuePress-theme-reco</a></span> <span data-v-1e2a0cc0><i class="iconfont reco-copyright" data-v-1e2a0cc0></i> <a data-v-1e2a0cc0><span data-v-1e2a0cc0>zenos</span>
            
          <span data-v-1e2a0cc0>2017 - </span>
          2020
        </a></span></div></div> <div data-v-319dd33c><main class="page"><div class="page-title" style="display:none;"><h1>Git本地多用户配置</h1> <hr> <div data-v-484a899e><i class="iconfont reco-account" data-v-484a899e><span data-v-484a899e>zenos</span></i> <i class="iconfont reco-date" data-v-484a899e><span data-v-484a899e>2020-04-26</span></i> <!----> <!----></div></div> <div class="theme-reco-content content__default" style="display:none;"><div class="custom-block tip"><p class="custom-block-title">使用场景</p> <p>自己同时拥有 GitHub、Gitee 等外网 git 账户或需要使用公司的 Gitlab 账户时，需要在本地配置多 git 账户</p></div> <p>一般来说，安装好 git 后，我们都会配置一个全局的 config 信息，就像这样：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 配置全局用户名，如 Github 上注册的用户名</span>
git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>name <span class="token string">&quot;718977623@qq.com&quot;</span>
<span class="token comment">// 配置全局邮箱，如 Github 上配置的邮箱</span>
git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>email <span class="token string">&quot;718977623@qq.com&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>但是你可能会碰到需要在一台电脑上配置多个用户信息的需求。此时就不能够用一个全局配置搞定一切了。</p> <p>比如因为我的个人电脑出了问题，我想要提交我的个人项目时，只能用公司配的电脑去提交。而公司的电脑配置的是私有的 gitlab 仓库，而我自己的项目存储在 github 上。这两个仓库不仅仓库地址不一样，仓库的用户名和邮箱都不一样。</p> <h2 id="具体步骤"><a href="#具体步骤" class="header-anchor">#</a> 具体步骤</h2> <h3 id="_1、清空全局配置"><a href="#_1、清空全局配置" class="header-anchor">#</a> 1、清空全局配置</h3> <p>在正式配置之前，我们先得把全局配置给清除掉（如果你配置过的话），执行命令：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>git config <span class="token operator">--</span>global <span class="token operator">--</span>list
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这会列出所有已经配置的全局配置，如果你发现其中有 user.name 和 user.email 信息，请执行以下命令将其清除掉：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>git config <span class="token operator">--</span>global <span class="token operator">--</span>unset user<span class="token punctuation">.</span>name
git config <span class="token operator">--</span>global <span class="token operator">--</span>unset user<span class="token punctuation">.</span>email
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="_2、生成秘钥"><a href="#_2、生成秘钥" class="header-anchor">#</a> 2、生成秘钥</h3> <p>钥对的保存位置默认在 ~/.ssh 目录下，我们先清理下这个目录中已存在的钥对信息，即删除其中的 <code>id_rsa</code>、<code>id_rsa.pub</code> 之类的公钥和密钥文件。</p> <p>首先我们开始生成 github 上的仓库钥对，通过 <code>-C</code> 参数填写 github 的邮箱：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>ssh-keygen -t rsa -C “718977623@qq.com”
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>按下 ENTER 键后，会有如下提示：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>Generatingpublic/privatersa key pair.Enter fileinwhich to save the key (/Users/jitwxs/.ssh/id_rsa):
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>在这里输入公钥的名字，默认情况是叫 <code>id_rsa</code>，为了和后面的 gitlab 配置区分，这里输入 <code>id_rsa_github</code>。输入完毕后，一路回车，钥对就生成完毕了。</p> <p>下面开始生成 gitlab 上的仓库钥对，步骤和上面一样：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>ssh-keygen -t rsa -C “zhangxiaoning”  //gitlab 生成时填入用户名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>生成的文件名称取名为<code>id_rsa_gitlab</code>。</p> <p><strong>文件会默认生成在 cmd 命令的所在的目录，生成的文件如下图</strong> <img src="https://zhangxiaoning.gitee.io/pond/Git/git_config_1.png" alt="avatar" title="cmd命令生成图片"></p> <h3 id="_3、拷贝-pub-文件"><a href="#_3、拷贝-pub-文件" class="header-anchor">#</a> 3、拷贝 pub 文件</h3> <p>将刚刚生成的<code>id_rsa_github</code>和<code>id_rsa_gitlab</code>，以及<code>id_rsa_github.pub</code>和<code>id_rsa_gitlab.pub</code>一同拷贝到<strong>C:\Users\zhangxn.ssh</strong>目录下</p> <h3 id="_4、管理秘钥"><a href="#_4、管理秘钥" class="header-anchor">#</a> 4、管理秘钥</h3> <p>通过以上步骤，公钥、密钥分别被添加到 git 服务器和本地了。下面我们需要在本地创建一个密钥配置文件，通过该文件，实现根据仓库的 remote 链接地址自动选择合适的私钥。</p> <p>编辑 <code>~/.ssh</code> 目录下的 config 文件，<strong><em>如果没有，请创建。没有后缀，文件名就叫 config</em></strong></p> <p>配置内容如下：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code># gitee.com
Host gitee
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa


# gitlab.company.com
Host 192.168.0.82
HostName 192.168.0.82
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>该文件分为多个用户配置，每个用户配置包含以下几个配置项：</p> <ul><li>Host：仓库网站的别名，随意取</li> <li>HostName：仓库网站的域名（PS：IP 地址应该也可以）</li> <li>User：仓库网站上的用户名</li> <li>IdentityFile：私钥的绝对路径</li></ul> <h3 id="_5、在-gitlab-项目网站中添加-ssh-公钥"><a href="#_5、在-gitlab-项目网站中添加-ssh-公钥" class="header-anchor">#</a> 5、在 gitlab 项目网站中添加 ssh 公钥</h3> <p>打开 <code>id_rsa_gitlab.pub</code> 文件中的内容到 SSH Keys 中，如下图（gitee、GitHub 类似）
<img src="https://zhangxiaoning.gitee.io/pond/Git/git_ssh.png" alt="avatar" title="秘钥管理"></p> <h3 id="_6、添加私钥"><a href="#_6、添加私钥" class="header-anchor">#</a> 6、添加私钥</h3> <p><code>在 Git Bash 中运行下列命令</code></p> <p>在上一步中，我们已经将公钥添加到了 github 或者 gitlab 服务器上，我们还需要将私钥添加到本地中，不然无法使用。添加命令也十分简单，如下：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>ssh-add ~/.ssh/id_rsa_github // 将 GitHub 私钥添加到本地
ssh-add ~/.ssh/id_rsa_gitlab // 将 GitLab 私钥添加到本地
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>添加完毕后，可以通过执行 <code>ssh-add -l</code> 验证下，如果都能显示出来和下面一样，就 OK 了。</p> <p><code>ssh-add -l</code></p> <h3 id="_7、仓库配置"><a href="#_7、仓库配置" class="header-anchor">#</a> 7、仓库配置</h3> <p>恭喜你！完成以上配置后，其实你已经基本完成了所有配置。分别进入附属于 github 和 gitlab 的仓库，此时都可以进行 git 操作了。但是别急，如果你此时提交仓库修改后，你会发现提交的用户名变成了你的系统主机名。</p> <p>这是因为 git 的配置分为三级别，<code>System —&gt; Global —&gt;Local</code>。<strong>System 即系统级别，Global 为配置的全局，Local 为仓库级别</strong>，优先级是 <code>Local &gt; Global &gt; System</code>。</p> <p>因为我们并没有给仓库配置用户名，又在一开始清除了全局的用户名，因此此时你提交的话，就会使用 System 级别的用户名，也就是你的系统主机名了。</p> <p>因此我们需要为每个仓库单独配置用户名信息，假设我们要配置 github 的某个仓库，<strong>进入该仓库后，执行</strong>：（如 git clone 后的代码仓库在，D:\JavaRepository\fwcloud-master，则先在 cmd 中切换到 D:\JavaRepository\fwcloud-master 路径下，再执行下列命令）</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>git config --local user.name &quot;zhangxiaoning&quot;
git config --local user.email &quot;zhangxiaoning&quot; //gitlab 的时候填用户名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>执行完毕后，通过以下命令查看本仓库的所有配置信息：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>git config --local --list
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">4/27/2020, 4:03:00 PM</span></div></footer> <!----></main> <!----> <div style="display:none;" data-v-319dd33c data-v-319dd33c><div class="comments-wrapper" data-v-319dd33c><!----></div></div></div></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-a81d141e data-v-a81d141e><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-a81d141e><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-a81d141e></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-a81d141e></path></svg></div><div class="kanbanniang" data-v-5775ee02><div class="banniang-container" style="display:;" data-v-5775ee02><div class="messageBox" style="right:68px;bottom:190px;display:none;" data-v-5775ee02>
      欢迎来到 方塘
    </div> <div class="operation" style="right:90px;bottom:40px;display:;" data-v-5775ee02><i class="kbnfont kbn-ban-home ban-home" data-v-5775ee02></i> <i class="kbnfont kbn-ban-message message" data-v-5775ee02></i> <i class="kbnfont kbn-ban-close close" data-v-5775ee02></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-5775ee02><i class="kbnfont kbn-ban-info info" data-v-5775ee02></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:none;" data-v-5775ee02></i></div> <canvas id="banniang" width="150" height="220" class="live2d" style="position:fixed;left:0px;bottom:0px;opacity:0.9;z-index:99999;" data-v-5775ee02></canvas></div> <div class="showBanNiang" style="display:none;" data-v-5775ee02>
    看板娘
  </div></div></div></div>
    <script src="/pond/assets/js/app.ae40f477.js" defer></script><script src="/pond/assets/js/3.4dddd738.js" defer></script><script src="/pond/assets/js/1.78b3a486.js" defer></script><script src="/pond/assets/js/14.0cad3209.js" defer></script>
  </body>
</html>
